from flask import request
from SQLConfig import app
from updateProjectFile import changeProjectFile

@app.route('/saveProjectData', methods=['Get', 'POST'])
def saveProjectData():  # put application's code here
    """
    
    """
    if request.method=='POST':
        patientId=request.json.get("patientId")
        rotation_axis = request.json.get("rotation_axis")
        pass_data = request.json.get("pass_data")
    elif request.method=='GET':
        patientId=request.json.get("patientId")
        rotation_axis = request.json.get("rotation_axis")
        pass_data = request.json.get("pass_data")
    
    changeProjectFile(patientId,"information","update","rotationAxis",rotation_axis)
    pass_data=list(pass_data)
    for i in range(len(pass_data)):
        temp=pass_data[i]
        changeProjectFile(patientId,"stlFiles","update",key=temp["index"], value={
            "color":temp["color"],
            "visible":temp["visible"],
            "showname":temp["show_names"],
            "transform_matrix":temp["transform_matrix"],
        })
    return "OK"